package com.batchengine.util;

import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
 * Created by  solutions
 * Author: sunil.incubator@yahoo.com
 * Date: Jul 24, 2009
 */
public class DateUtil {

    public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
    public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

    public static final String AM = "AM";
    public static final String PM = "PM";

    private DateUtil() {
    }

    public static long getNextHour() {

        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR, c.get(Calendar.HOUR) + 1);
        return c.getTimeInMillis();
    }

    public static String formatSecsToHHMMSS(long secods) {

        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.set(Calendar.AM_PM, Calendar.AM);
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, (int) secods);
        return sdf.format(c.getTime());
    }

    public static Date parseDate(String dateStr) {

        if (null == dateStr) {
            return null;
        }
        try {
            return dateFormat.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String parseDate(Date date) {

        if (null == date) {
            return null;
        }
        try {
            return dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
